/**
 * Created by liyl on 2017/7/31.
 */
import weiboConfig from '../../../../api/config/channel/weibo-config'
import * as globalTypes from '../../../../mutation-types'
/**
 * 获取appUrl 和 appKey
 * @param {Object} data
 * @param {String} [data.name] 微博名称
 * @param {String} [data.weiboId] 微博Id
 */
export const getWeiboUrlAndAppkey = ({commit, state, rootState, dispatch}, data) => {
  return weiboConfig.getWeiboUrlAndAppkey(data)
    .then(response => {
      if (response.success) {
        return response
      }
    })
    .catch(() => {
      commit(globalTypes.SET_ERROR, 'message.default_tips')
    })
}
/**
 * 保存微博账号
 * @param data
 * @param data.to_peer  消息分发技能组
 * @param data.robot 机器人ID
 * @param data.convert_words 转人工触发词
 * @param data.welcome_msg 欢迎语
 * @param data.welcomePushTime 欢迎语推送时机
 * @param data.webchat_csr 启用满意度评价
 * @param data.name 微博名称
 * @param data.weiboId && data._id && data.accessId 微博账号ID
 * @param data.appUrl url
 * @param data.appKey appKey
 * @param data.access_token access_token
 * @param data.account 当前账户的account
 * @param data.robotType 机器人类型
 * @param data.platform 平台来源
 */
export const saveBindWeiboDetail = ({commit, state, rootState, dispatch}, data) => {
  return weiboConfig.saveBindWeiboDetail(data)
    .then(response => {
      return response
    })
    .catch(() => {
      commit(globalTypes.SET_ERROR, 'message.default_tips')
    })
}
/**
 * 查询或者是刷新微博列表
 * @param data
 * @param data.limit  && data.page
 */
export const queryWeiboList = ({commit, state, rootState, dispatch}, data) => {
  return weiboConfig.queryWeiboList(data)
    .then(response => {
      return response
    })
    .catch(() => {
      commit(globalTypes.SET_ERROR, 'message.default_tips')
    })
}
export const queryWeiboCfgById = ({commit, state, rootState, dispatch}, data) => {
  return weiboConfig.queryWeiboCfgById(data)
    .then(response => {
      return response
    })
    .catch(() => {
      commit(globalTypes.SET_ERROR, 'message.default_tips')
    })
}
export const remvoeWeiboConfig = ({commit, state, rootState, dispatch}, data) => {
  return weiboConfig.remvoeWeiboConfig(data)
    .then(response => {
      return response
    })
    .catch(() => {
      commit(globalTypes.SET_ERROR, 'message.default_tips')
    })
}
